<template>
  <div>
    <a-row :gutter="20">
      <a-col :span="8">
        <a-card shadow="hover" class="mgb20" style="height: 252px">
          <div class="user-info">
            <img src="../../assets/favicon2.png" class="user-avator" alt />
            <div class="user-info-cont">
              <div class="user-info-name">{{ name }}</div>
              <div>{{ role }}</div>
            </div>
          </div>
          <div class="user-info-list">
            上次登录时间：
            <span>2019-11-01</span>
          </div>
          <div class="user-info-list">
            上次登录地点：
            <span>东莞</span>
          </div>
        </a-card>
        <a-card shadow="hover" style="height: 252px">
          <div slot="header" class="clearfix">
            <span>语言详情</span>
          </div>
          Vue <a-progress :percentage="71.3" color="#42b983"></a-progress>JavaScript
          <a-progress :percentage="24.1" color="#f1e05a"></a-progress>CSS
          <a-progress :percentage="13.7"></a-progress>HTML
          <a-progress :percentage="5.9" color="#f56c6c"></a-progress>
        </a-card>
      </a-col>
      <a-col :span="16">
        <a-row :gutter="20" class="mgb20">
          <a-col :span="8">
            <a-card shadow="hover" :body-style="{ padding: '0px' }">
              <div class="grid-content grid-con-1">
                <i class="el-icon-lx-people grid-con-icon"><a-icon type="user"></a-icon></i>
                <div class="grid-cont-right">
                  <div class="grid-num">1234</div>
                  <div>用户访问量</div>
                </div>
              </div>
            </a-card>
          </a-col>
          <a-col :span="8">
            <a-card shadow="hover" :body-style="{ padding: '0px' }">
              <div class="grid-content grid-con-2">
                <i class="el-icon-lx-notice grid-con-icon"><a-icon type="global"></a-icon></i>
                <div class="grid-cont-right">
                  <div class="grid-num">321</div>
                  <div>系统消息</div>
                </div>
              </div>
            </a-card>
          </a-col>
          <a-col :span="8">
            <a-card shadow="hover" :body-style="{ padding: '0px' }">
              <div class="grid-content grid-con-3">
                <i class="el-icon-lx-goods grid-con-icon"><a-icon type="pay-circle"></a-icon></i>
                <div class="grid-cont-right">
                  <div class="grid-num">5000</div>
                  <div>数量</div>
                </div>
              </div>
            </a-card>
          </a-col>
        </a-row>
        <a-card shadow="hover" style="height: 403px">
          <div slot="header" class="clearfix">
            <span>待办事项</span>
            <a-button style="float: right; padding: 3px 0" type="text">添加</a-button>
          </div>
          <a-table :show-header="false" :data="todoList" style="width: 100%">
            <a-table-column width="40">
              <template slot-scope="scope">
                <a-checkbox v-model="scope.row.status"></a-checkbox>
              </template>
            </a-table-column>
            <a-table-column>
              <template slot-scope="scope">
                <div class="todo-item" :class="{ 'todo-item-del': scope.row.status }">{{ scope.row.title }}</div>
              </template>
            </a-table-column>
            <a-table-column width="60">
              <template>
                <i class="el-icon-edit"></i>
                <i class="el-icon-delete"></i>
              </template>
            </a-table-column>
          </a-table>
        </a-card>
      </a-col>
    </a-row>
    <a-row :gutter="20">
      <a-col :span="12">
        <a-card shadow="hover">
          <!-- <schart ref="bar" class="schart" canvasId="bar" :options="options"></schart> -->
          <div ref="myChart" :style="{ height: '400px'}"></div>
        </a-card>
      </a-col>
      <a-col :span="12">
        <a-card shadow="hover">
          <!-- <schart ref="line" class="schart" canvasId="line" :options="options2"></schart> -->
          <div id="main" :style="{ height: '400px'}"></div>
        </a-card>
      </a-col>
    </a-row>
  </div>
</template>

<script>
import Schart from 'vue-schart'
import OperatorCache from '@/utils/cache/OperatorCache'
export default {
  data() {
    return {
      name: OperatorCache.info['UserName'],
      todoList: [
        {
          title: '今天要修复100个bug',
          status: false,
        },
        {
          title: '今天要修复100个bug',
          status: false,
        },
        {
          title: '今天要写100行代码加几个bug吧',
          status: false,
        },
        {
          title: '今天要修复100个bug',
          status: false,
        },
        {
          title: '今天要修复100个bug',
          status: true,
        },
        {
          title: '今天要写100行代码加几个bug吧',
          status: true,
        },
      ],
      data: [
        {
          name: '2018/09/04',
          value: 1083,
        },
        {
          name: '2018/09/05',
          value: 941,
        },
        {
          name: '2018/09/06',
          value: 1139,
        },
        {
          name: '2018/09/07',
          value: 816,
        },
        {
          name: '2018/09/08',
          value: 327,
        },
        {
          name: '2018/09/09',
          value: 228,
        },
        {
          name: '2018/09/10',
          value: 1065,
        },
      ],
      options: {
        type: 'bar',
        title: {
          text: '最近一周各品类销售图',
        },
        xRorate: 25,
        labels: ['周一', '周二', '周三', '周四', '周五'],
        datasets: [
          {
            label: '家电',
            data: [234, 278, 270, 190, 230],
          },
          {
            label: '百货',
            data: [164, 178, 190, 135, 160],
          },
          {
            label: '食品',
            data: [144, 198, 150, 235, 120],
          },
        ],
      },
      options2: {
        type: 'line',
        title: {
          text: '最近几个月各品类销售趋势图',
        },
        labels: ['6月', '7月', '8月', '9月', '10月'],
        datasets: [
          {
            label: '家电',
            data: [234, 278, 270, 190, 230],
          },
          {
            label: '百货',
            data: [164, 178, 150, 135, 160],
          },
          {
            label: '食品',
            data: [74, 118, 200, 235, 90],
          },
        ],
      },
      queryParam: {},
    }
  },
  components: {
    Schart,
  },
  computed: {
    role() {
      return OperatorCache.info['RoleNames']
    },
  },
  mounted() {
    console.log(OperatorCache)
    this.showEcharts()
    this.showEcharts1()
    this.HomeData()
  },

  methods: {
    showEcharts() {
      // 基于准备好的dom，初始化echarts实例
      let myChart = this.$echarts.init(this.$refs.myChart)
      // 绘制图表
      myChart.setOption({
        legend: {
          selectedMode: true, //可点击
          data: ['注册用户', '累计用户量'],
          bottom: 0,
        },
        grid: {
          left: 100,
        },
        xAxis: [
          {
            type: 'category',
            data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
            splitLine: {
              //不显示分割线
              show: false,
            },
          },
        ],
        yAxis: [
          {
            type: 'value',
            name: '注册用户',
            splitLine: {
              //显示分割线
              show: true,
            },
          },
          {
            type: 'value',
            name: '累计用户量',
            //	                        axisLabel: {
            //	                            formatter: '{value} °C'
            //	                        },
            splitLine: {
              show: true,
            },
          },
        ],
        series: [
          {
            name: '注册用户',
            type: 'bar',
            data: [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3],
            itemStyle: {
              color: 'rgba(132, 136, 211, 1)',
            },
          },
          {
            name: '累计用户量',
            type: 'line',
            yAxisIndex: 1, //索引从0开始
            data: [2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3, 23.4, 23.0, 16.5, 12.0, 6.2],
            itemStyle: {
              color: 'rgba(91, 245, 204, 1)',
            },
          },
        ],
      })
      //建议加上以下这一行代码，不加，当浏览器窗口缩小时，echarts显示不全。
      window.addEventListener('resize', function () {
        myChart.resize()
      })
    },
    showEcharts1(){
      var chartDom = document.getElementById('main');
var myChart = this.$echarts.init(chartDom);
var option;

option = {
  legend: {
    top: 'bottom'
  },
  toolbox: {
    show: true,
    feature: {
      mark: { show: true },
      dataView: { show: true, readOnly: false },
      restore: { show: true },
      saveAsImage: { show: true }
    }
  },
  series: [
    {
      name: 'Nightingale Chart',
      type: 'pie',
      radius: [50, 150],
      center: ['50%', '50%'],
      roseType: 'area',
      itemStyle: {
        borderRadius: 8
      },
      data: [
        { value: 40, name: 'rose 1' },
        { value: 38, name: 'rose 2' },
        { value: 32, name: 'rose 3' },
        { value: 30, name: 'rose 4' },
        { value: 28, name: 'rose 5' },
      ]
    }
  ]
};

option && myChart.setOption(option);
    },
    HomeData(){
      this.queryParam.Condition = ""
      this.$http.post("/Base_Manage/Home/GetHomeData",{Search: this.queryParam}).then(res=>{
        console.log(res)
      })
    }
  },
}
</script>


<style scoped>
.a-row {
  margin-bottom: 20px;
}

.grid-content {
  display: flex;
  align-items: center;
  height: 100px;
}

.grid-cont-right {
  flex: 1;
  text-align: center;
  font-size: 14px;
  color: #999;
}

.grid-num {
  font-size: 30px;
  font-weight: bold;
}

.grid-con-icon {
  font-size: 50px;
  width: 100px;
  height: 100px;
  text-align: center;
  line-height: 100px;
  color: #fff;
}

.grid-con-1 .grid-con-icon {
  background: rgb(45, 140, 240);
}

.grid-con-1 .grid-num {
  color: rgb(45, 140, 240);
}

.grid-con-2 .grid-con-icon {
  background: rgb(100, 213, 114);
}

.grid-con-2 .grid-num {
  color: rgb(45, 140, 240);
}

.grid-con-3 .grid-con-icon {
  background: rgb(242, 94, 67);
}

.grid-con-3 .grid-num {
  color: rgb(242, 94, 67);
}

.user-info {
  display: flex;
  align-items: center;
  padding-bottom: 20px;
  border-bottom: 2px solid #ccc;
  margin-bottom: 20px;
}

.user-avator {
  width: 120px;
  height: 120px;
  border-radius: 50%;
}

.user-info-cont {
  padding-left: 50px;
  flex: 1;
  font-size: 14px;
  color: #999;
}

.user-info-cont div:first-child {
  font-size: 30px;
  color: #222;
}

.user-info-list {
  font-size: 14px;
  color: #999;
  line-height: 25px;
}

.user-info-list span {
  margin-left: 70px;
}

.mgb20 {
  margin-bottom: 20px;
}

.todo-item {
  font-size: 14px;
}

.todo-item-del {
  text-decoration: line-through;
  color: #999;
}

.schart {
  width: 100%;
  height: 300px;
}
</style>
